import java.awt.*;

/** 
 * A LayoutManager implementation designed for laying out
 * _only_ JComponents of type ArduinoPin.
 * 
 * @author Mihai Moraru
 */
public class ArduinoLayout implements LayoutManager {
	public void addLayoutComponent(String name, Component comp) {}

	public void removeLayoutComponent(Component comp) {}

	public Dimension minimumLayoutSize(Container parent)
	{
		return new Dimension(minW, minH);
	}

	public Dimension preferredLayoutSize(Container parent)
	{
		return new Dimension(prefW, prefH);
	}
	
	public void layoutContainer(Container parent)
	{
		int N = parent.getComponentCount();
		int W = parent.getWidth();
		int H = parent.getHeight();
		for(int i = 0; i < N; ++i) if(parent.getComponent(i) instanceof ArduinoPin) {
			ArduinoPin p = (ArduinoPin)parent.getComponent(i);
			Dimension d = p.getPreferredSize();
			int x = (int)((p.getPreferredX()*W)-d.width/2);
			int y = (int)((p.getPreferredY()*H)-d.height/2);
			p.setBounds(x, y, d.width, d.height);
		}
	}

	private int minW = 10;
	private int minH = 10;
	private int prefW = 1200;
	private int prefH = 1035;
}
